package com.zxl.test;

import java.io.IOException;

public class Base64 {

	public static void main(String args[]){
		String str = "Hello World!";
		str = encode(str);
		System.out.println("str:" + str);
		String str1 = new String(decode(str));
		System.out.println("str:" + str1);
	}
	
	/**
	 * 编码
	 * @param str
	 * @return
	 */
	public static String encode(String str) {
		return new sun.misc.BASE64Encoder().encode(str.getBytes());
	}

	/**
	 * 解码
	 * @param str
	 * @return
	 */
	public static byte[] decode(String str) {
		byte[] bt = null;
		try {
			sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
			bt = decoder.decodeBuffer(str);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return bt;
	}  
}
